package alex.thread;

import java.util.concurrent.*;

public class SingleExecutorDeadLock {

    // 只有一个任务线程可用
    private static ExecutorService executorService = Executors.newSingleThreadExecutor();

    public static class AnotherCallable implements Callable<String> {
        @Override
        public String call() {
            System.out.println("In Another callable");
            return "another success!";
        }
    }

    public static class MyCallable implements Callable<String> {
        @Override
        public String call() throws Exception {
            System.out.println("In my callable");

            // 因为使用的线程池
            Future<String> future = executorService.submit(new AnotherCallable());
            return "My Callable success: " + future.get();
        }
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        MyCallable myCallable = new MyCallable();
        Future<String> future = executorService.submit(myCallable);
        System.out.println(future.get());
        System.out.println("Over");
        executorService.shutdown();
    }
}
